function DbStock()
{
	this.stock_data ;
	
	this.get_db_data = function()
	{
		return this.stock_data;
	}
	
	this.load_db_datastring = function()
	{
		var strdata = localStorage.getItem( 'stocks');
		return strdata;
	}
	
	this.set_db_datastring = function(strdata)
	{
		var js_data = [];
		if(strdata!=null && strdata!="" )
		{
			 js_data=jQuery.evalJSON(strdata);
		}
		this.set_db_data(js_data);
	}
	
	this.load_db_data = function()
	{
		var data = localStorage.getItem( 'stocks');
		var js_data = [];
		if(data!=null && data!="" )
		{
			 js_data=jQuery.evalJSON(data);
		}
		
		this.stock_data = js_data;

	};
	
	this.set_db_data = function(data)
	{
		this.stock_data = data;
		localStorage.setItem( 'stocks',jQuery.toJSON(data));
	}
	
	
	this.get_symbol_info = function(symbol)
	{
		var _stock = {};
		_stock.alarm_max_price='';
		_stock.alarm_min_price='';
		_stock.buy_price='';
		if(symbol.length!=8 ) return _stock;
		 var js_data = this.stock_data;
		 var i;
		 for(i=0;i<js_data.length;i++)
		 {
			 
		 	  if(js_data[i]['symbol'] == symbol)
		 	  {
		 	  	return js_data[i];
		 	  }
		 }		
		 return _stock;
	}
	
	this.add_symbol = function(symbol)
	{
		 if(!(symbol.length==8 ||symbol.length==6)) return false;
		 if(symbol.length==6)
		 {
				if(symbol=='000001')
				{
					symbol = 'sh'+symbol;
				}else if(symbol>=600000)
				{
					symbol = 'sh'+symbol;
				}else{
					symbol = 'sz'+symbol;
				}				 	
		 }
		 var js_data = this.stock_data;
		 var exist = false;
		 for(i=0;i<js_data.length;i++)
		 {
		 	  if(js_data[i]['symbol'] == symbol)
		 	  {
		 	  	exist = true;
		 	  }
		 }
		 if(!exist)
		 {
		 	  var stock = {};
				stock['symbol'] = symbol;
				js_data.push(stock);
		 }
		 this.set_db_data(js_data);		
	}
	
	this.get_sina_query = function()
	{
		 var ret = "";
		 var js_data = this.stock_data;
		 var ss = [];
		 for(i=0;i<js_data.length;i++)
		 {
		 	  ss.push(js_data[i]['symbol']);
		 }
		 return ss.join();
	}
	
	this.delete_symbol = function(symbol)
	{
		 if(symbol.length!=8 ) return false;
		 var js_data = this.stock_data;
		 var exist = false;
		 var new_data = [];
		 for(i=0;i<js_data.length;i++)
		 {
		 	  if(js_data[i]['symbol'] == symbol)
		 	  {
		 	  	exist = true;
		 	  }else
		 	  	new_data.push(js_data[i]);
		 }
		 if(exist)
		 {
		 	  this.set_db_data(new_data);		
		 }
		 
	}
		
	this.set_alarm_price = function(symbol,ptype,price)
	{
		 if(jQuery.inArray(ptype, ['alarm_max_price','alarm_min_price','buy_price'])==-1) return false;
		 var js_data = this.stock_data;
		 var exist = false;
		 
		 for(i=0;i<js_data.length;i++)
		 {
		 	  if(js_data[i]['symbol'] == symbol)
		 	  {
		 	  	js_data[i][ptype] = price;
		 	  	exist = true;
		 	  }
		 }
		 if(!exist)
		 {
		 	  var stock = {};
				stock['symbol'] = symbol;
				stock[ptype] = price;
				js_data.push(stock);
		 }
		 this.set_db_data(js_data);
	};
		
	this.load_db_data();
	
}